import React, { Component } from 'react';
import { withRouter } from 'react-router-dom';
import * as tools from '../../config/tools'
import * as api from '../../config/api.js'
class Popup extends Component {
    constructor(args) {
        super();
        this.state = {
            party : {
                OrderTimeList:[]
            },
        }
    }
    show(Props){
        this.setState({
            party: Props.party,
        })
    }
    componentWillReceiveProps(nextProps) {
        this.show(nextProps)
    }
    componentDidMount() {
        this.show(this.props)
    }
    ok() {
        let params = {
            checkUpOrderId: localStorage.getItem('checkUpOrderId'),
            partyId: localStorage.getItem('partyId'),
            isTime: this.state.party.isTime,
            isUpdate: '0'
        }
        if (this.state.party.isTime === '1') {
            let chooseItem = JSON.parse(localStorage.getItem('chooseItem')) || ''
            params = {
                ...params,
                checkupDate: chooseItem.schedulingDate + ' ' + chooseItem.schedulingPeriod,
                schedulingDate: chooseItem.schedulingDate,
                schedulingPeriod: chooseItem.schedulingPeriod,
                orderedPersonCnt: chooseItem.orderedPersonCnt,
            }
        }
        api.updateCheckUpParty(params).then((data) => {
            if (tools.checkResult(data)) {
                tools.toast.success('预约成功');
                this.props.history.push(`/record`)
            } else {
                tools.toast.error('网络错误');
            }
        })
    }
    render() {
        let party = this.state.party;
        let chooseItem = JSON.parse(localStorage.getItem('chooseItem')) || '';
        return (
                <div id="popup_modal" className="beizhu reveal-modal">
                    <div className="beizhu-content">
                        <h1>友邦保险有限公司</h1>
                        <div className="tishi-content reveal-modal-main">
                            <dl>
                                <dt>客户</dt>
                                <dd>{localStorage.getItem('personName')}</dd>
                            </dl>
                            {party.isTime === '1'?<dl>
                                <dt>体检时间</dt>
                                <dd>{chooseItem.schedulingDate + ' ' + chooseItem.schedulingPeriod}</dd>
                            </dl>:null}
                            <dl>
                                <dt>体检机构</dt>
                                <dd>{party.partyName}</dd>
                            </dl>
                            <dl>
                                <dt>地址</dt>
                                <dd>{party.partyAddress}</dd>
                            </dl>
                            <dl>
                                <dt>电话</dt>
                                <dd>{party.partyTel}</dd>
                            </dl>
                        </div>
                        <div className="mui-clearfix"></div>
                        <div className="beizhu-btn">
                            <span className="close-reveal-modal half">取 消</span>
                            <span className="half" onClick={()=>this.ok()} >确 定</span>
                        </div>
                    </div>
                </div>
        );
    }
}

export default withRouter(Popup);